using JGSY.CMS.LowCode.Platform.Application.DTOs;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 团队应用服务接口
    /// 提供团队管理相关的业务逻辑操作
    /// </summary>
    public interface ITeamAppService
    {
        /// <summary>
        /// 获取所有团队
        /// </summary>
        /// <returns>团队列表</returns>
        Task<IEnumerable<TeamDto>> GetAllAsync();

        /// <summary>
        /// 根据ID获取团队
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <returns>团队信息</returns>
        Task<TeamDto?> GetByIdAsync(long id);

        /// <summary>
        /// 根据编码获取团队
        /// </summary>
        /// <param name="code">团队编码</param>
        /// <returns>团队信息</returns>
        Task<TeamDto?> GetByCodeAsync(string code);

        /// <summary>
        /// 根据部门获取团队列表
        /// </summary>
        /// <param name="departmentId">部门ID</param>
        /// <returns>团队列表</returns>
        Task<IEnumerable<TeamDto>> GetByDepartmentAsync(long departmentId);

        /// <summary>
        /// 获取用户所在团队列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns>团队列表</returns>
        Task<IEnumerable<TeamDto>> GetUserTeamsAsync(long userId);

        /// <summary>
        /// 分页获取团队列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="departmentId">部门ID</param>
        /// <param name="teamType">团队类型</param>
        /// <param name="status">状态过滤</param>
        /// <returns>分页团队列表</returns>
        Task<(IEnumerable<TeamDto> Items, int TotalCount)> GetPagedAsync(
            int pageIndex, 
            int pageSize, 
            string? keyword = null, 
            long? departmentId = null,
            string? teamType = null,
            byte? status = null);

        /// <summary>
        /// 创建团队
        /// </summary>
        /// <param name="teamDto">团队信息</param>
        /// <returns>创建的团队</returns>
        Task<TeamDto> CreateAsync(TeamDto teamDto);

        /// <summary>
        /// 更新团队
        /// </summary>
        /// <param name="teamDto">团队信息</param>
        /// <returns>更新的团队</returns>
        Task<TeamDto> UpdateAsync(TeamDto teamDto);

        /// <summary>
        /// 删除团队
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteAsync(long id);

        /// <summary>
        /// 批量删除团队
        /// </summary>
        /// <param name="ids">团队ID列表</param>
        /// <returns>删除的数量</returns>
        Task<int> BatchDeleteAsync(IEnumerable<long> ids);

        /// <summary>
        /// 更新团队状态
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <param name="status">状态</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateStatusAsync(long id, byte status);

        /// <summary>
        /// 设置团队负责人
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <param name="leaderId">负责人ID</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetLeaderAsync(long id, long? leaderId);

        /// <summary>
        /// 添加团队成员
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userId">用户ID</param>
        /// <param name="role">成员角色</param>
        /// <returns>是否添加成功</returns>
        Task<bool> AddMemberAsync(long teamId, long userId, string? role = null);

        /// <summary>
        /// 批量添加团队成员
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userIds">用户ID列表</param>
        /// <param name="role">成员角色</param>
        /// <returns>添加的数量</returns>
        Task<int> BatchAddMembersAsync(long teamId, IEnumerable<long> userIds, string? role = null);

        /// <summary>
        /// 移除团队成员
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userId">用户ID</param>
        /// <returns>是否移除成功</returns>
        Task<bool> RemoveMemberAsync(long teamId, long userId);

        /// <summary>
        /// 批量移除团队成员
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userIds">用户ID列表</param>
        /// <returns>移除的数量</returns>
        Task<int> BatchRemoveMembersAsync(long teamId, IEnumerable<long> userIds);

        /// <summary>
        /// 更新团队成员角色
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userId">用户ID</param>
        /// <param name="role">成员角色</param>
        /// <returns>是否更新成功</returns>
        Task<bool> UpdateMemberRoleAsync(long teamId, long userId, string role);

        /// <summary>
        /// 获取团队成员列表
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="activeOnly">仅获取活跃成员</param>
        /// <returns>成员列表</returns>
        Task<IEnumerable<UserDto>> GetTeamMembersAsync(long teamId, bool activeOnly = true);

        /// <summary>
        /// 检查用户是否为团队成员
        /// </summary>
        /// <param name="teamId">团队ID</param>
        /// <param name="userId">用户ID</param>
        /// <returns>是否为团队成员</returns>
        Task<bool> IsMemberAsync(long teamId, long userId);

        /// <summary>
        /// 检查团队编码是否存在
        /// </summary>
        /// <param name="code">团队编码</param>
        /// <param name="excludeId">排除的团队ID</param>
        /// <returns>是否存在</returns>
        Task<bool> CodeExistsAsync(string code, long? excludeId = null);

        /// <summary>
        /// 检查是否可以删除团队
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <returns>是否可以删除</returns>
        Task<bool> CanDeleteAsync(long id);

        /// <summary>
        /// 转移团队到其他部门
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <param name="newDepartmentId">新部门ID</param>
        /// <returns>是否转移成功</returns>
        Task<bool> TransferToDepartmentAsync(long id, long newDepartmentId);

        /// <summary>
        /// 获取团队统计信息
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <returns>统计信息</returns>
        Task<object> GetTeamStatisticsAsync(long id);

        /// <summary>
        /// 搜索团队
        /// </summary>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns>搜索结果</returns>
        Task<(IEnumerable<TeamDto> Items, int TotalCount)> SearchAsync(
            string keyword, 
            int pageIndex = 1, 
            int pageSize = 20);

        /// <summary>
        /// 获取团队绩效统计
        /// </summary>
        /// <param name="id">团队ID</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns>绩效统计</returns>
        Task<object> GetTeamPerformanceAsync(long id, DateTime? startDate = null, DateTime? endDate = null);
    }
}
